import Vue from 'vue'
import VueRouter from 'vue-router'
import Detail from '../views/Detail.vue'
import List from '../views/List.vue'
import Login from '../views/Login.vue'
import Verify from '../views/Verify.vue'

import InsureLayout from '@/views/layout/InsureLayout'
import Layout11654 from '@/views/layout/11654'
import Layout13253 from '@/views/layout/13253'
import Layout11804 from '@/views/layout/11804'
import Layout11837 from '@/views/layout/11837'
import Layout113305 from '@/views/layout/113305'

Vue.use(VueRouter)

const routes = [
	{
		path: '/',
		name: 'List',
		component: List
	},
	{
		path: '/verify',
		name: 'Verify',
		component: Verify
	},
	{
		path: '/login',
		name: 'Login',
		component: Login
	},
	{
		path: '/detail',
		name: 'detail',
		component: Detail
	},
	{
		path: '/insure',
		name: 'Insure',
		component: InsureLayout,
		redirect: 'input',
		children: [
			{
				path: 'input',
				name: 'InsureInput',
				component: () => import('@/views/insure/Input.vue')
			},

			{
				path: 'wait',
				name: 'Wait',
				component: () => import('@/views/insure/Wait.vue')
			},
			{
				path: 'stamp',
				name: 'Stamp',
				component: () => import('@/views/insure/Stamp.vue')
			},
			{
				path: 'payment',
				name: 'Payment',
				component: () => import('@/views/insure/Payment.vue')
			},
			{
				path: 'payment-no-require',
				name: 'Payment-No-Require',
				component: () => import('@/views/insure/Payment.vue')
			},
			{
				path: 'success',
				name: 'Success',
				component: () => import('@/views/insure/Success.vue')
			},
			{
				path: 'pay-success',
				name: 'PaySuccess',
				component: () => import('@/views/insure/PaySuccess.vue')
			}
		]
	},
	{
		path: '/11654',
		name: 'I11654',
		component: Layout11654,
		redirect: '/11654/input',
		children: [
			{
				path: 'input',
				meta: {
					name: 'InsureInput'
				},
				component: () => import('@/views/11654/Input.vue')
			},

			{
				path: 'payment',
				meta: {
					name: 'Payment-No-Require'
				},
				component: () => import('@/views/11654/Payment.vue')
			},

			{
				path: 'success',
				meta: {
					name: 'Success'
				},
				component: () => import('@/views/11654/Success.vue')
			}
		]
	},
	{
		path: '/13253',
		name: 'I13253',
		component: Layout13253,
		redirect: '/13253/input',
		children: [
			{
				path: 'input',
				meta: {
					name: 'InsureInput'
				},
				component: () => import('@/views/13253/Input')
			},

			{
				path: 'payment',
				meta: {
					name: 'Payment-No-Require'
				},
				component: () => import('@/views/13253/Payment.vue')
			},

			{
				path: 'success',
				meta: {
					name: 'Success'
				},
				component: () => import('@/views/13253/personSuccess.vue'),
				props: ($route) => ({ businessId: $route.query.businessId })
			},
			{
				path: 'qiye-success',
				meta: {
					name: 'QiyeSuccess'
				},
				component: () => import('@/views/13253/qiyeSuccess.vue'),
				props: ($route) => ({ businessId: $route.query.businessId })
			}
		]
	},
	{
		path: '/113305',
		name: 'I113305',
		component: Layout113305,
		redirect: '/113305/input',
		children: [
			{
				path: 'input',
				meta: {
					name: 'InsureInput'
				},
				component: () => import('@/views/113305/Input')
			},

			{
				path: 'payment',
				meta: {
					name: 'Payment-No-Require'
				},
				component: () => import('@/views/113305/Payment.vue')
			},

			{
				path: 'success',
				meta: {
					name: 'Success'
				},
				component: () => import('@/views/113305/personSuccess.vue'),
				props: ($route) => ({ businessId: $route.query.businessId })
			},
			{
				path: 'qiye-success',
				meta: {
					name: 'QiyeSuccess'
				},
				component: () => import('@/views/113305/qiyeSuccess.vue'),
				props: ($route) => ({ businessId: $route.query.businessId })
			}
		]
	},
	{
		path: '/11804',
		name: 'I11804',
		component: Layout11804,
		redirect: '/11804/input',
		children: [
			{
				path: 'input',
				meta: {
					name: 'InsureInput'
				},
				component: () => import('@/views/11804/Input.vue')
			},

			{
				path: 'payment',
				meta: {
					name: 'Payment-No-Require'
				},
				component: () => import('@/views/11804/Payment.vue')
			},

			{
				path: 'success',
				meta: {
					name: 'Success'
				},
				component: () => import('@/views/11804/Success.vue')
			}
		]
	},
	{
		path: '/11837',
		name: 'I11837',
		component: Layout11837,
		redirect: '/11837/input',
		children: [
			{
				path: 'input',
				meta: {
					name: 'InsureInput'
				},
				component: () => import('@/views/11837/Input/Input.vue')
			},
			{
				path: 'submit',
				meta: {
					name: 'SubmitFile',
					keepAlive: true
				},
				props: (route) => ({
					businessId: route.query.businessId
				}),
				component: () => import('@/views/11837/SubmitFile.vue')
			},

			{
				path: 'submit-success',
				meta: {
					name: 'submit-success',
					keepAlive: true
				},
				props: (route) => ({
					businessId: route.query.businessId
				}),
				component: () => import('@/views/11837/SubmitSuccess.vue')
			},

			{
				path: 'order',
				meta: {
					name: 'Order'
				},
				component: () => import('@/views/11837/Order.vue')
			},
			{
				path: 'login',
				meta: {
					name: 'Login'
				},
				component: () => import('@/views/11837/Login.vue')
			}
		]
	},
	{
		path: '/insure-car',
		name: 'InsureInputCar',
		component: () => import('@/views/insure/InputCar.vue')
	},
	// {
	// 	path: '/about',
	// 	name: 'about',
	// 	// route level code-splitting
	// 	// this generates a separate chunk (about.[hash].js) for this route
	// 	// which is lazy-loaded when the route is visited.
	// 	component: () =>
	// 		import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
	// },
	// {
	// 	path: '/payment',
	// 	name: 'payment',
	// 	// route level code-splitting
	// 	// this generates a separate chunk (about.[hash].js) for this route
	// 	// which is lazy-loaded when the route is visited.
	// 	component: () =>
	// 		import(/* webpackChunkName: "about" */ '../views/Payment.vue')
	// },
	// {
	// 	path: '/success',
	// 	name: 'success',
	// 	// route level code-splitting
	// 	// this generates a separate chunk (about.[hash].js) for this route
	// 	// which is lazy-loaded when the route is visited.
	// 	component: () =>
	// 		import(/* webpackChunkName: "about" */ '../views/Success.vue')
	// },
	{
		path: '/order/list',
		name: 'OrderLst',
		// route level code-splitting
		// this generates a separate chunk (about.[hash].js) for this route
		// which is lazy-loaded when the route is visited.
		component: () =>
			import(/* webpackChunkName: "about" */ '../views/OrderList.vue')
	}
]

const router = new VueRouter({
	routes
})

import beforeEach11837 from '@/views/11837/router/each'
const childrenEach = [beforeEach11837]

import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css' // Progress 进度条样式
import { isUploadPayFile } from '@/api' // 判断是否已上传凭证

router.beforeEach(async (to, from, next) => {
	NProgress.start()

	let isNexted = false
	function __next(p) {
		next(p)
		isNexted = true
	}

	for (let routerEach of childrenEach) {
		await routerEach(to, from, __next)
		if (isNexted) return
	}
	if (['Stamp', 'Payment'].includes(to.name)) {
		// 是否校验果手机号码
		if (sessionStorage.getItem('isVerifyBusiness') !== to.query.businessId) {
			next({
				path: '/verify',
				query: {
					businessId: to.query.businessId
				}
			})
			return
		}
		isUploadPayFile(to.query.businessId).then((res) => {
			if (res.isUploadPayFile) {
				next('/insure/success')
			} else {
				next()
			}
		})
		return
	}
	next()
})
router.afterEach(() => {
	NProgress.done()
})
export default router

export { routes }
